package com.deepgames.mud.gobject.data;

import java.util.Map;
import java.util.Set;

/**
 * Simple Gobject Bean.
 * 
 * @author Zack Hoffmann
 * @version 0.1
 *
 */
public class Gobject {
	
	private String gobjectID;
	private String shortName;
	private String longName;
	private String shortDesc;
	private String longDesc;
	private Map<String,String> meta;
	
	public Gobject(String gobjectID, String shortName, String longName,
		String shortDesc, String longDesc, String formattedMeta) {
		this.gobjectID = gobjectID;
		this.shortName = shortName;
		this.longName = longName;
		this.shortDesc = shortDesc;
		this.longDesc = longDesc;
		this.setFormattedMetadata(formattedMeta);
	}
	
	public String getGobjectID() {
		return this.gobjectID;
	}
	
	public void setMetadata(String key, String value) {
		this.meta.put(key, value);
	}
	
	public String getMetadata(String key) {
		return this.meta.get(key);
	}
	
	public String getFormattedMetadata() {
		String formatted = "";
		Set<String> keys = this.meta.keySet();
		
		for (String key:keys) {
			formatted += key + "|" + this.meta.get(key) + "|";
		}
		
		return formatted;
	}
	
	public void setFormattedMetadata(String formatted) {
		String[] metaSet = formatted.split("|");
		
		for (int i = 0; i <  metaSet.length-1; i += 2) {
			this.meta.put(metaSet[i],metaSet[i+1]);
		}
	}

	public String getShortName() {
		return shortName;
	}

	public void setShortName(String shortName) {
		this.shortName = shortName;
	}

	public String getLongName() {
		return longName;
	}

	public void setLongName(String longName) {
		this.longName = longName;
	}

	public String getShortDesc() {
		return shortDesc;
	}

	public void setShortDesc(String shortDesc) {
		this.shortDesc = shortDesc;
	}

	public String getLongDesc() {
		return longDesc;
	}

	public void setLongDesc(String longDesc) {
		this.longDesc = longDesc;
	}
	
	public String getGobTypeCode() {
		String gobTypeCode = "U";
		Class<?> thisClass = this.getClass();
		
		if (thisClass.equals(Gobject.class)) {
			gobTypeCode = "G";
		}
		else if (thisClass.equals(Character.class)) {
			gobTypeCode = "C";
		}
		else if (thisClass.equals(Player.class)) {
			gobTypeCode = "P";
		}
		else if (thisClass.equals(Item.class)) {
			gobTypeCode = "I";
		}
		else if (thisClass.equals(Room.class)) {
			gobTypeCode = "R";
		}
		else if (thisClass.equals(Zone.class)) {
			gobTypeCode = "Z";
		}
		
		return gobTypeCode;
	}
	
}
